﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL.DataFramework;
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("BC")]
namespace BE.DataFramework
{
    public class ConnectionsBE
    {
        public int? iConnectionId { get; set; }
        public string sConnectionName { get; set; }
        public int? iConnectorId { get; set; }
        public string sConnectionString { get; set; }
        public bool bActive { get; set; }

        internal ConnectionsBE Create()
        {
            try
            {
                ConnectionsBE result = new ConnectionsBE();
                using (ConnectionsDAL<ConnectionsBE> datos = new ConnectionsDAL<ConnectionsBE>())
                {
                    result = datos.Create(
                        this.sConnectionName,
                        (int)this.iConnectorId,
                        this.sConnectionString,
                        this.bActive);
                }

                return result;
            }
            catch (Exception ex)
            {
                throw new Exception("ConnectionsBE - Create - ", ex);
            }
        }
        internal ConnectionsBE Update()
        {
            try
            {
                ConnectionsBE result = new ConnectionsBE();
                using (ConnectionsDAL<ConnectionsBE> datos = new ConnectionsDAL<ConnectionsBE>())
                {
                    result = datos.Update(
                        (int)this.iConnectorId,
                        this.sConnectionName,
                        (int)this.iConnectorId,
                        this.sConnectionString,
                        this.bActive);
                }

                return result;
            }
            catch (Exception ex)
            {
                throw new Exception("ConnectionsBE - Update - ", ex);
            }
        }
        internal int Delete()
        {
            try
            {
                int result = 0;
                using (ConnectionsDAL<ConnectionsBE> datos = new ConnectionsDAL<ConnectionsBE>())
                {
                    result = datos.Delete(
                        (int)this.iConnectionId);
                }

                return result;
            }
            catch (Exception ex)
            {
                throw new Exception("ConnectionsBE - Delete - ", ex);
            }
        }
        internal List<ConnectionsBE> Select()
        {
            try
            {
                List<ConnectionsBE> result = new List<ConnectionsBE>();
                using (ConnectionsDAL<ConnectionsBE> datos = new ConnectionsDAL<ConnectionsBE>())
                {
                    result = datos.Select(
                        (int)this.iConnectionId,
                        this.sConnectionName,
                        (int)this.iConnectorId,
                        this.sConnectionString,
                        this.bActive);
                }

                return result;
            }
            catch (Exception ex)
            {
                throw new Exception("ConnectionsBE - Select - ", ex);
            }
        }
        public override string ToString()
        {
            return this.sConnectionName;
        }
    }
}
